/*
* Copyright (c) 2011 Connection Road.  All rights reserved.
* This program and the accompanying material are made available
* under the terms of the Eclipse Public Licnese v1.0 which is
* available at http://www.eclipse.org/legal/epl-v10.html
*/

using Microsoft.Win32;

namespace CrSyncFilesUtils
{
    public class RegistryManager
    {

        public RegistryManager(string keyName)
        {
            KeyName = keyName;
        }

        public string KeyName { get; set; }
        public RegistryKey RegistryInfo { get; set; }
        public string Value { get; set; }

        public bool ContainsKey(string key)
        {
            RegistryInfo = Registry.CurrentUser.OpenSubKey(KeyName);
            
            if(RegistryInfo != null)
            {
                Value = (string)RegistryInfo.GetValue(key, string.Empty);
                return !string.IsNullOrEmpty(Value);
            }

            return false;
        }


        public bool SetValueForKey(string value, string key)
        {
            RegistryInfo = Registry.CurrentUser.CreateSubKey(KeyName);
            if (RegistryInfo != null)
            {
                RegistryInfo.SetValue(key, value);
                return true;
            }
            return false;
        }

        public string GetValueForKey(string key, string defaultValue)
        {
            RegistryInfo = Registry.CurrentUser.OpenSubKey(KeyName);

            if (RegistryInfo != null)
            {
                Value = (string) RegistryInfo.GetValue(key, defaultValue);
                return Value;
            }

            return defaultValue;
        }

        
    }
}
